package com.woniuxy.movice.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池工具类
 * @author lxq
 * @data 2019年9月12日下午2:40:41
 */
public class ThreadPoolUtil {
	public  static final ExecutorService threadPool;
	private static final int core;//cpu核数
	private static final long KEEP_ALIVE_TIME=3L;//存活时间
	static {
		core = Runtime.getRuntime().availableProcessors();
		threadPool = new ThreadPoolExecutor(core + 1, core + 1, KEEP_ALIVE_TIME, TimeUnit.SECONDS,
				new LinkedBlockingDeque<Runnable>(), Executors.defaultThreadFactory(),
				new ThreadPoolExecutor.CallerRunsPolicy());
	}
}
